#!/bin/bash
#leao:Thu Aug 22 11:19:30 AM CST 2024
cpfun(){
    for val in `ls -a $1`; do
        if [ "$val" = "." -o "$val" = ".." ]; then
            continue
        elif [ "$val" = "$2" ];then
            continue
        else
            cp -r "$val" "$2"
        fi
    done
}
path1=$1
path2=$2

if [ -z "$path1" ] || [ -z "$path2" ]; then
    echo "ERROR: argcs"
    exit 1
fi

if [ ! -d "$path2" ]; then
    echo "ERROR: 目标路径不存在是否新建? y/Y 取消退出程序 n/N"
    read -r val
    case $val in
        [yY]*)
            mkdir -p "$path2"
            cpfun "$path1" "$path2"
            ;;
        [n/N]*)
            exit 1
            ;;
        *)
            echo "Invalid option. Exiting."
            exit 1
            ;;
    esac
else
    cpfun "$path1" "$path2"
fi
   